//
//  MapViewController.m
//  Tiger
//
//  Created by King on 11-9-21.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "MapViewController.h"
#import "Tiger.h"


@implementation MapViewController


@synthesize mapView;


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	//地图类型
	mapView.mapType = MKMapTypeStandard;
	mapView.showsUserLocation=YES;
	
	
	self.mapView.delegate=self;
	
	CLLocationCoordinate2D coordinate;
    coordinate.latitude = 31.220185;
    coordinate.longitude = 121.267899;
    mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, 5000, 5000);
	
	
	CGFloat lat = 31.220185;
	CGFloat lng = 121.267899;
	
	CLLocationCoordinate2D newCoord = {lat, lng};
	Tiger *pin = [[Tiger alloc] init];
	pin.title = @"上虎（上海）精密工具有限公司";
	pin.subtitle = @"上海市闵行区华漕镇联友路669号";
	pin.coordinate = newCoord;
	
	[mapView addAnnotation:pin];
	[pin release];



}

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
	MKPinAnnotationView *pinView = nil;
	if(annotation != mapView.userLocation)
	{
		static NSString *defaultPinID = @"com.invasivecode.pin";
		pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
		if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
										  initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
		pinView.pinColor = MKPinAnnotationColorRed;
		pinView.canShowCallout = YES;
		pinView.animatesDrop = YES;
	}
	else {
		[mapView.userLocation setTitle:@"我的位置"];
	}
	return pinView;
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
	NSLog(@"Error resolving coordinates: %@", [error localizedDescription]);
	geocoder.delegate = nil;
	[geocoder autorelease];
} 


- (void)reverseGeocoder:didFindPlacemark:(MKPlacemark *)placemark {
	NSLog(@"2323");
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

	self.mapView = nil;
}


- (void)dealloc {
    [super dealloc];

	[mapView release];
}

@end


















